function isInArray(arr, value) {
	for (var i = 0; i < arr.length; i++) {
		if (value == arr[i]) {
			return true;
		}
	}
	return false;
}

function loadForm(jsonObj) {
	for (var key in jsonObj) {
		if (document.getElementById(key) != null) {
			if (document.getElementById(key).type == 'text') {
				document.getElementById(key).value = jsonObj[key];
			} else if (document.getElementById(key).type == 'number') {
				document.getElementById(key).value = jsonObj[key];
			} else if (document.getElementById(key).type == 'hidden') {
				document.getElementById(key).value = jsonObj[key];
			} else if (document.getElementById(key).tagName == 'TEXTAREA') {
				document.getElementById(key).value = jsonObj[key];
			} else if (document.getElementById(key).tagName == 'SELECT') {
				document.getElementById(key).value = jsonObj[key];
			}

		}

		if (document.getElementsByName(key + "1").length > 0) {
			var key_name = key + "1";
			var this_key = document.getElementsByName(key + "1");
			if (this_key[0].type == 'checkbox') {
				var this_str = jsonObj[key].split(',');
				for (var i = 0; i < this_str.length; i++) {
					jQuery("input[name='" + key_name + "'][value='" + this_str[i] + "']").attr("checked", "checked");
				}
			}
			if (this_key[0].type == 'radio') {
				jQuery("input[name='" + key_name + "'][value='" + jsonObj[key] + "']").attr("checked", "checked");
			}

		}

	}
}


// // 选择日期
// function pickDate(selectid){
// 	plus.nativeUI.pickDate( function(e){
// 		var d=e.date;
// //		console.log( "选择的日期："+d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate() );
// 		jQuery(selectid).val(d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate());
// 	},function(e){
// //		console.log( "未选择日期："+e.message );
// 	});
// }


jQuery.fn.serializeObject = function() {
	var a, o, h, i, e;
	a = this.serializeArray();
	o = {};
	h = o.hasOwnProperty;
	for (i = 0; i < a.length; i++) {
		e = a[i];
		if (!h.call(o, e.name)) {
			o[e.name] = e.value;
		}
	}
	return o;
};


Date.prototype.format = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份 
		"d+": this.getDate(), //日 
		"h+": this.getHours(), //小时 
		"m+": this.getMinutes(), //分 
		"s+": this.getSeconds(), //秒 
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		}
	}
	return fmt;
}

function getPreMonth(date) {
	var arr = date.split('-');
	var year = arr[0]; //获取当前日期的年份  
	var month = arr[1]; //获取当前日期的月份  
	var day = arr[2]; //获取当前日期的日  
	var days = new Date(year, month, 0);
	days = days.getDate(); //获取当前日期中月的天数  
	var year2 = year;
	var month2 = parseInt(month) - 1;
	if (month2 == 0) {
		year2 = parseInt(year2) - 1;
		month2 = 12;
	}
	var day2 = day;
	var days2 = new Date(year2, month2, 0);
	days2 = days2.getDate();
	if (day2 > days2) {
		day2 = days2;
	}
	if (month2 < 10) {
		month2 = '0' + month2;
	}
	var t2 = year2 + '-' + month2 + '-' + day2;
	return t2;
}



function getNextMonth(date) {
	var arr = date.split('-');
	var year = arr[0]; //获取当前日期的年份  
	var month = arr[1]; //获取当前日期的月份  
	var day = arr[2]; //获取当前日期的日  
	var days = new Date(year, month, 0);
	days = days.getDate(); //获取当前日期中的月的天数  
	var year2 = year;
	var month2 = parseInt(month) + 1;
	if (month2 == 13) {
		year2 = parseInt(year2) + 1;
		month2 = 1;
	}
	var day2 = day;
	var days2 = new Date(year2, month2, 0);
	days2 = days2.getDate();
	if (day2 > days2) {
		day2 = days2;
	}
	if (month2 < 10) {
		month2 = '0' + month2;
	}

	var t2 = year2 + '-' + month2 + '-' + day2;
	return t2;
}

function datetime_init() {
	(function($) {
		var btns = $('.btn');
		btns.each(function(i, btn) {
			btn.addEventListener('tap', function() {
				var _self = this;
				if (_self.picker) {
					_self.picker.show(function(rs) {
						_self.picker.dispose();
						_self.picker = null;
					});
				} else {
					var optionsJson = this.getAttribute('data-options') || '{}';
					var options = JSON.parse(optionsJson);
					var id = this.getAttribute('id');

					_self.picker = new $.DtPicker(options);
					_self.picker.show(function(rs) {

						jQuery("#" + id).text(rs.text);
						if (id == "newClientList_date") {
							loadNewClientList();
						} else if (id == 'arriveAtSchoolList_date') {
							loadArriveAtSchoolList();
						} else if (id == 'inviteUpSchool_date') {
							loadinviteUpSchoolList();
						} else if (id == "followUpClientList_date") {
							loadFollowUpClientList();
						} else if (id == "studentList_date") {
							loadStudentList();
						} else if (id == 'clientManageList_date') {
							loadClientManageList();


						} else if (id == 'followUpClientList_date') {
							loadFollowUpClientList();
						} else if (id == 'awaitAppraisalList_date') {
							loadAwaitAppraisalList_date();
						} else if (id == 'appraisal_date') {
							loadappraisalList();
						} else if (id == "SalerPerformance_date") {
							loadSalerPerformance();

						} else if (id == "teacher_query_date") {
							loadTeacherTotal();
						} else if (id == 'record_date') {
							refreshInfo('auto')
						} else if (id == 'kudb_date') {
							numTotal();
							//							fxSchoolSelect();
						} else if (id == 'channeldonetimeEnd' || id == 'channeldonetimeStart') {
							loadChannelTotal();
						} else if (id == 'counselorDonetimeEnd' || id == 'counselorDonetimeStart') {
							loadCounselorTotal();
						} else if (id == 'knockdownDonetimeEnd' || id == 'knockdownDonetimeStart') {
							loadKnockdownTotal();
						} else if (id == "teacherDonetimeStart" || id == "teacherDonetimeStart") {
							loadTeacherTotal();
						} else if (id == 'rectorDonetimeStart' || id == 'rectorownDonetimeEnd') {
							homeContent();
						}
						_self.picker.dispose();
						_self.picker = null;
					});
				}

			}, false);
		});
	})(mui);

	//年月日
	(function($) {
		var btns = $('.form_date');
		btns.each(function(i, btn) {
			btn.addEventListener('tap', function() {
				var _self = this;
				if (_self.picker) {
					_self.picker.show(function(rs) {
						_self.picker.dispose();
						_self.picker = null;
					});
				} else {
					var optionsJson = this.getAttribute('data-options') || '{}';
					var options = JSON.parse(optionsJson);
					var id = this.getAttribute('id');
					_self.picker = new $.DtPicker(options);
					_self.picker.show(function(rs) {
						console.log("=====" + rs)
						var year = rs.text.split('-')[0];
						var month = rs.text.split('-')[1];
						var day = rs.text.split('-')[2];
						jQuery("#" + id).val(getPreMonth(new Date(year, month, day).format('yyyy-MM-dd')));

						_self.picker.dispose();
						_self.picker = null;
					});
				}

			}, false);
		});
	})(mui);
	//	年月日:时分秒
	(function($) {
		var btns = $('.form_date_ss');
		btns.each(function(i, btn) {
			btn.addEventListener('tap', function() {
				var _self = this;
				if (_self.picker) {
					_self.picker.show(function(rs) {
						_self.picker.dispose();
						_self.picker = null;
					});
				} else {
					var optionsJson = this.getAttribute('data-options') || '{}';
					var options = JSON.parse(optionsJson);
					var id = this.getAttribute('id');
					_self.picker = new $.DtPicker(options);
					_self.picker.show(function(rs) {
						jQuery("#" + id).val(rs + ":00");
						_self.picker.dispose();
						_self.picker = null;
					});
				}

			}, false);
		});
	})(mui);
	//年月日时分
	(function($) {
		var btns = $('.form_date_mm');
		btns.each(function(i, btn) {
			btn.addEventListener('tap', function() {
				var _self = this;
				if (_self.picker) {
					_self.picker.show(function(rs) {
						_self.picker.dispose();
						_self.picker = null;
					});
				} else {
					var optionsJson = this.getAttribute('data-options') || '{}';
					var options = JSON.parse(optionsJson);
					var id = this.getAttribute('id');
					_self.picker = new $.DtPicker(options);
					_self.picker.show(function(rs) {
						console.log("======" + rs.text)
						jQuery("#" + id).val(rs.text);

						_self.picker.dispose();
						_self.picker = null;
					});
				}

			}, false);
		});
	})(mui);

}


function selectCheckout(startdate, enddate, stuname, stutel, onechannelid, twochannelid, ) {
	var data = {};
	if (startdate != "" && enddate != "" && startdate != null && enddate != null) {
		data['createdatestart'] = startdate;
		data['createdateend'] = enddate;
	} else if (stuname != "") {
		data['stuname'] = stuname;
	} else if (stutel != "") {
		data['stutel'] = stutel;
	} else if (onechannelid != "") {
		data['onechannelid'] = onechannelid;
	} else if (twochannelid != "") {
		data['twochannelid'] = twochannelid;
	} else {

	}
	return data;
}

function getSchools(data) {
	(function($, doc) {
		$.ready(function() {

			//普通示例
			var userPicker = new $.PopPicker();
			userPicker.setData(data);
			var showUserPickerButton = doc.getElementById('showSchoolPicker');


			showUserPickerButton.addEventListener('tap', function(event) {
				userPicker.show(function(items) {
					showUserPickerButton.innerText = items[0].text;
					schoolid = items[0].value;
					refreshInfo("auto");
				});
			}, false);

		});
	})(mui, document);
}


function getSchools1(data) {
	(function($, doc) {
		$.ready(function() {
			//普通示例
			var userPicker = new $.PopPicker();
			userPicker.setData(data);
			var showSchoolPickerButton = doc.getElementById("showSchoolPicker")
			showSchoolPickerButton.addEventListener('tap', function(event) {
				userPicker.show(function(items) {
					showSchoolPickerButton.innerText = items[0].text;
					schoolid = items[0].value;
					loadChannelTotal();
				});
			}, false);
		});
	})(mui, document);
}

function getSchools2(data) {
	(function($, doc) {
		$.ready(function() {
			//普通示例
			var userPicker = new $.PopPicker();
			userPicker.setData(data);
			var showSchoolPickerButton = doc.getElementById("showSchoolPicker")
			showSchoolPickerButton.addEventListener('tap', function(event) {
				userPicker.show(function(items) {
					showSchoolPickerButton.innerText = items[0].text;
					schoolid = items[0].value;
					loadCounselorTotal();

				});
			}, false);
		});
	})(mui, document);
}

function getSchools3(data) {
	(function($, doc) {
		$.ready(function() {
			//普通示例
			var userPicker = new $.PopPicker();
			userPicker.setData(data);
			var showSchoolPickerButton = doc.getElementById("showSchoolPicker")
			showSchoolPickerButton.addEventListener('tap', function(event) {
				userPicker.show(function(items) {
					showSchoolPickerButton.innerText = items[0].text;
					schoolid = items[0].value;
					loadKnockdownTotal();
				});
			}, false);
		});
	})(mui, document);
}

function getSchools4(data) {
	(function($, doc) {
		$.ready(function() {
			//普通示例
			var userPicker = new $.PopPicker();
			userPicker.setData(data);
			var showSchoolPickerButton = doc.getElementById("showSchoolPicker")
			showSchoolPickerButton.addEventListener('tap', function(event) {
				userPicker.show(function(items) {
					showSchoolPickerButton.innerText = items[0].text;
					schoolid = items[0].value;
					homeContent();
				});
			}, false);
		});
	})(mui, document);
}

function getText(idstr) {
	var textStr = jQuery("#" + idstr + "").find("option:selected").text();
	return textStr;
}

function judgeNull(strData) {
	console.log()
	var num = 0;
	for (var i = 0; i < strData.length; i++) {
		var str = jQuery("#" + strData[i] + "").val();
		console.log(strData[i] + "=====" + str);
		if (str != null && str != undefined && str != "") {
			num = num + 1
		}
	}
	console.log(num);
	if (num == strData.length) {
		return true;
	} else {
		return false;
	}

}
//获取当前时间
function CurentTime() {
	var now = new Date();

	var year = now.getFullYear(); //年
	var month = now.getMonth() + 1; //月
	var day = now.getDate(); //日

	var hh = now.getHours(); //时
	var mm = now.getMinutes(); //分

	var clock = year + "-";

	if (month < 10)
		clock += "0";

	clock += month + "-";

	if (day < 10)
		clock += "0";

	clock += day + " ";

	if (hh < 10)
		clock += "0";

	clock += hh + ":";
	if (mm < 10) clock += '0';
	clock += mm;
	clock += ":00"
	return (clock);
}
//获取本月第一天 
function startCurrentMonth() {
	var now = new Date();
	var year = now.getFullYear(); //年
	var month = now.getMonth() + 1; //月
	var day = "1"; //日       
	var hh = "0"; //时
	var mm = "0"; //分
	var ss = ":00";
	var startTime = year + "-";

	if (month < 10)
		startTime += "0";

	startTime += month + "-";

	if (day < 10)
		startTime += "0";

	startTime += day + " ";

	if (hh < 10)
		startTime += "0";

	startTime += hh + ":";
	if (mm < 10) startTime += '0';
	startTime += mm;
	startTime += ss
	return (startTime);
}

//获取本月最后一天
function endCurrentMonth() {
	var now = new Date();
	var year = now.getFullYear(); //年
	var month = now.getMonth() + 1; //月
	var day = mGetDate(); //日
	var hh = "23"; //时
	var mm = "59"; //分
	var ss = ":59";
	var endTime = year + "-";

	if (month < 10)
		endTime += "0";

	endTime += month + "-";

	if (day < 10)
		endTime += "0";

	endTime += day + " ";

	if (hh < 10)
		endTime += "0";

	endTime += hh + ":";
	if (mm < 10) endTime += '0';
	endTime += mm;
	endTime += ss
	return (endTime);
}


//获取本月第一天 
function startCurrentMonth1() {
	var now = new Date();
	var year = now.getFullYear(); //年
	var month = now.getMonth() + 1; //月
	var day = "1"; //日       

	var startTime = year + "-";

	if (month < 10)
		startTime += "0";

	startTime += month + "-";

	if (day < 10)
		startTime += "0";
	   startTime += day 

	
	
	return (startTime);
}

//获取本月最后一天
function endCurrentMonth1() {
	var now = new Date();
	var year = now.getFullYear(); //年
	var month = now.getMonth() + 1; //月
	var day = mGetDate(); //日

	var endTime = year + "-";

	if (month < 10)
		endTime += "0";
	
	endTime += month + "-";
	
	if (day < 10)
		endTime += "0";
	endTime += day 

	
	
	
	return (endTime);
}

function mGetDate() {
	var date = new Date();
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var d = new Date(year, month, 0);
	return d.getDate();
}
